<?php
/**
 * Created by Command.
 * User: Vito
 */

declare (strict_types = 1);

namespace app\logic;

use app\model\PollingRecord;
use app\model\PollingType;

class PollingRecordLogic extends BaseLogic
{

    /**
     * 设置模型
     * @return string
     */
    protected function getModelName(): string
    {
        return PollingRecord::class;
    }

    /**
     * @Description: 获取记录内容详情
     * @author: xiayu <cb1071403016@126.com>
     * @param [type] $params
     * @Date: 2022-11-04 16:30:14
     * @version: 1.0.0
     * @return [type]
     */
    public function getDetail($params){

        // print_r($params);
        // die;
        $contentWhere['pid'] = $params['type_id'];
        
        $content = PollingType::getPollingType($contentWhere);

        // 记录内的全部内容id
        $all_id = $params['normal_id'] . ',' . $params['no_normal_id'];
        $allIdList = explode(',', $all_id);

        // 记录内的正常内容id
        $normalList = explode(',', $params['normal_id']);

        // 记录内异常内容id
        $no_normalList = explode(',',$params['no_normal_id']);

        foreach ($content as $key => $value) {
            
            if(!$this->normalState($value['id'], $normalList)){
                $content[$key]['status'] = '正常';
            }
            if (!$this->noNormalState($value['id'], $no_normalList)) {
                $content[$key]['status'] = '异常';
            }
            if (!$this->unknownState($value['id'], $allIdList)) {
                $content[$key]['status'] = '未知';
            }
        }

        return $content;
    }
    /**
     * @Description: 检测该内容是否正常
     * @author: xiayu <cb1071403016@126.com>
     * @param [type] $id      内容id
     * @param [type] $list    正常数据id
     * @Date: 2022-11-04 16:31:42
     * @version: 1.0.0
     * @return [type]
     */
    public function normalState($id,$list){
        $result = true;

        foreach ($list as $key => $value) {
            if($id == $value){
                $result = false;
            }
        }

        return $result;
    }
    /**
     * @Description: 检测该内容是否异常
     * @author: xiayu <cb1071403016@126.com>
     * @param [type] $id      内容id
     * @param [type] $list    异常数据id
     * @Date: 2022-11-04 16:31:42
     * @version: 1.0.0
     * @return [type]
     */
    public function noNormalState($id, $list)
    {
        $result = true;

        foreach ($list as $key => $value) {
            if ($id == $value) {
                $result = false;
            }
        }

        return $result;
    }
    /**
     * @Description: 检测该内容是否存在
     * @author: xiayu <cb1071403016@126.com>
     * @param [type] $id        
     * @param [type] $list
     * @Date: 2022-11-04 16:35:55
     * @version: 1.0.0
     * @return [type]
     */
    public function unknownState($id, $list)
    {
        $result = false;

        foreach ($list as $key => $value) {
            if ($id == $value) {
                $result = true;
            }
        }

        return $result;
    }
}
